function test_suite = everymatTests
  initTestSuite;

function p = setup
  repos = glib.gi.repos();
  p = repos.Everymat;

%% Test subsref

function test_fetchClass_stepwise(p)
  c = p.Noisy;
  
function test_fetchClass_chained(p)
  repos = glib.gi.repos();
  c = repos.Everymat.Noisy;

function test_createObject_noConstruct_stepwise(p)
  c = p.Thing;
  o = c();

function test_createObject_noConstruct_chained(p)
  repos = glib.gi.repos();
  o = p.Thing();
  o = repos.Everymat.Thing();

function test_createObject_construct_stepwise(p)
  c = p.Thing;
  o = c('prop_int', 3);
  assertTrue(o.prop_int == 3);

function test_createObject_construct_chained(p)
  repos = glib.gi.repos();
  o = p.Thing('prop_int', 3);
  assertTrue(o.prop_int == 3);
  o = repos.Everymat.Thing('prop_int', 3);
  assertTrue(o.prop_int == 3);

function test_void_stepwise(p)
  f = p.void;
  f();

function test_void_chained(p)
  repos = glib.gi.repos();
  p.void();
  repos.Everymat.void();

function test_weave_stepwise(p)
  f = p.weave;
  f(1, 2, 3);
  [a b c] = f(1, 2, 3);
  assertEqual(a, 2);
  assertEqual(b, int32(3));
  assertEqual(c, logical(1));

function test_weave_chained(p)
  repos = glib.gi.repos();
  p.weave(1, 2, 3);
  [a b c] = p.weave(1, 2, 3);
  assertEqual(a, 2);
  assertEqual(b, int32(3));
  assertEqual(c, logical(1));
  repos.Everymat.weave(1, 2, 3);
  [a b c] = repos.Everymat.weave(1, 2, 3);
  assertEqual(a, 2);
  assertEqual(b, int32(3));
  assertEqual(c, logical(1));

function test_Thing_void_stepwise(p)
  o = p.Thing();
  f = o.void;
  f(o);

function test_Thing_void_chained(p)
  o = p.Thing();
  o.void();

function test_Thing_weave_stepwise(p)
  o = p.Thing();
  f = o.weave;
  f(o, 1, 2, 3);
  [a b c] = f(o, 1, 2, 3);
  assertEqual(a, 2);
  assertEqual(b, int32(3));
  assertEqual(c, logical(1));

function test_Thing_weave_chained(p)
  o = p.Thing();
  o.weave(1, 2, 3);
  [a b c] = o.weave(1, 2, 3);
  assertEqual(a, 2);
  assertEqual(b, int32(3));
  assertEqual(c, logical(1));

%% Test argument conversion

function test_pass_bool_true(p)
  assertEqual(p.pass_bool(logical(1)), logical(1));
function test_pass_bool_false(p)
  assertEqual(p.pass_bool(logical(0)), logical(0));
function test_pass_bool_int8(p)
  assertEqual(p.pass_bool(int8(3)), logical(1));
function test_pass_bool_uint8(p)
  assertEqual(p.pass_bool(uint8(3)), logical(1));
function test_pass_bool_int16(p)
  assertEqual(p.pass_bool(int16(3)), logical(1));
function test_pass_bool_uint16(p)
  assertEqual(p.pass_bool(uint16(3)), logical(1));
function test_pass_bool_int32(p)
  assertEqual(p.pass_bool(int32(3)), logical(1));
function test_pass_bool_uint32(p)
  assertEqual(p.pass_bool(uint32(3)), logical(1));
function test_pass_bool_int64(p)
  assertEqual(p.pass_bool(int64(3)), logical(1));
function test_pass_bool_uint64(p)
  assertEqual(p.pass_bool(uint64(3)), logical(1));
function test_pass_bool_float(p)
  assertEqual(p.pass_bool(single(2.3)), logical(1));
function test_pass_bool_double(p)
  assertEqual(p.pass_bool(2.3), logical(1));

function test_pass_gint8_true(p)
  assertEqual(p.pass_gint8(logical(1)), int8(1));
function test_pass_gint8_int8(p)
  assertEqual(p.pass_gint8(int8(3)), int8(3));
function test_pass_gint8_uint8(p)
  assertEqual(p.pass_gint8(uint8(200)), int8(-56));
function test_pass_gint8_int16(p)
  assertEqual(p.pass_gint8(int16(400)), int8(-112));
function test_pass_gint8_uint16(p)
  assertEqual(p.pass_gint8(uint16(400)), int8(-112));
function test_pass_gint8_int32(p)
  assertEqual(p.pass_gint8(int32(400)), int8(-112));
function test_pass_gint8_uint32(p)
  assertEqual(p.pass_gint8(uint32(400)), int8(-112));
function test_pass_gint8_int64(p)
  assertEqual(p.pass_gint8(int64(400)), int8(-112));
function test_pass_gint8_uint64(p)
  assertEqual(p.pass_gint8(uint64(400)), int8(-112));
function test_pass_gint8_float(p)
  assertEqual(p.pass_gint8(single(2.3)), int8(2));
function test_pass_gint8_double(p)
  assertEqual(p.pass_gint8(2.3), int8(2));

function test_pass_guint8_true(p)
  assertEqual(p.pass_guint8(logical(1)), uint8(1));
function test_pass_guint8_int8(p)
  assertEqual(p.pass_guint8(int8(-100)), uint8(156));
function test_pass_guint8_uint8(p)
  assertEqual(p.pass_guint8(uint8(200)), uint8(200));
function test_pass_guint8_int16(p)
  assertEqual(p.pass_guint8(int16(400)), uint8(144));
function test_pass_guint8_uint16(p)
  assertEqual(p.pass_guint8(uint16(400)), uint8(144));
function test_pass_guint8_int32(p)
  assertEqual(p.pass_guint8(int32(400)), uint8(144));
function test_pass_guint8_uint32(p)
  assertEqual(p.pass_guint8(uint32(400)), uint8(144));
function test_pass_guint8_int64(p)
  assertEqual(p.pass_guint8(int64(400)), uint8(144));
function test_pass_guint8_uint64(p)
  assertEqual(p.pass_guint8(uint64(400)), uint8(144));
function test_pass_guint8_float(p)
  assertEqual(p.pass_guint8(single(2.3)), uint8(2));
function test_pass_guint8_double(p)
  assertEqual(p.pass_guint8(2.3), uint8(2));

function test_pass_gint16_true(p)
  assertEqual(p.pass_gint16(logical(1)), int16(1));
function test_pass_gint16_int8(p)
  assertEqual(p.pass_gint16(int8(-100)), int16(-100));
function test_pass_gint16_uint8(p)
  assertEqual(p.pass_gint16(uint8(200)), int16(200));
function test_pass_gint16_int16(p)
  assertEqual(p.pass_gint16(int16(400)), int16(400));
function test_pass_gint16_uint16(p)
  assertEqual(p.pass_gint16(uint16(60000)), int16(-5536));
function test_pass_gint16_int32(p)
  assertEqual(p.pass_gint16(int32(100000)), int16(-31072));
function test_pass_gint16_uint32(p)
  assertEqual(p.pass_gint16(uint32(100000)), int16(-31072));
function test_pass_gint16_int64(p)
  assertEqual(p.pass_gint16(int64(100000)), int16(-31072));
function test_pass_gint16_uint64(p)
  assertEqual(p.pass_gint16(uint64(100000)), int16(-31072));
function test_pass_gint16_float(p)
  assertEqual(p.pass_gint16(single(2.3)), int16(2));
function test_pass_gint16_double(p)
  assertEqual(p.pass_gint16(2.3), int16(2));

function test_pass_guint16_true(p)
  assertEqual(p.pass_guint16(logical(1)), uint16(1));
function test_pass_guint16_int8(p)
  assertEqual(p.pass_guint16(int8(-100)), uint16(65436));
function test_pass_guint16_uint8(p)
  assertEqual(p.pass_guint16(uint8(200)), uint16(200));
function test_pass_guint16_int16(p)
  assertEqual(p.pass_guint16(int16(400)), uint16(400));
function test_pass_guint16_uint16(p)
  assertEqual(p.pass_guint16(uint16(60000)), uint16(60000));
function test_pass_guint16_int32(p)
  assertEqual(p.pass_guint16(int32(100000)), uint16(34464));
function test_pass_guint16_uint32(p)
  assertEqual(p.pass_guint16(uint32(100000)), uint16(34464));
function test_pass_guint16_int64(p)
  assertEqual(p.pass_guint16(int64(100000)), uint16(34464));
function test_pass_guint16_uint64(p)
  assertEqual(p.pass_guint16(uint64(100000)), uint16(34464));
function test_pass_guint16_float(p)
  assertEqual(p.pass_guint16(single(2.3)), uint16(2));
function test_pass_guint16_double(p)
  assertEqual(p.pass_guint16(2.3), uint16(2));

function test_pass_gint32_true(p)
  assertEqual(p.pass_gint32(logical(1)), int32(1));
function test_pass_gint32_int8(p)
  assertEqual(p.pass_gint32(int8(-100)), int32(-100));
function test_pass_gint32_uint8(p)
  assertEqual(p.pass_gint32(uint8(200)), int32(200));
function test_pass_gint32_int16(p)
  assertEqual(p.pass_gint32(int16(400)), int32(400));
function test_pass_gint32_uint16(p)
  assertEqual(p.pass_gint32(uint16(60000)), int32(60000));
function test_pass_gint32_int32(p)
  assertEqual(p.pass_gint32(int32(100000)), int32(100000));
function test_pass_gint32_uint32(p)
  assertEqual(p.pass_gint32(uint32(2147483658)), int32(-2147483638));
function test_pass_gint32_int64(p)
  assertEqual(p.pass_gint32(int64(1101659111434)), int32(-2147483638));
function test_pass_gint32_uint64(p)
  assertEqual(p.pass_gint32(uint64(1101659111434)), int32(-2147483638));
function test_pass_gint32_float(p)
  assertEqual(p.pass_gint32(single(2.3)), int32(2));
function test_pass_gint32_double(p)
  assertEqual(p.pass_gint32(2.3), int32(2));

function test_pass_guint32_true(p)
  assertEqual(p.pass_guint32(logical(1)), uint32(1));
function test_pass_guint32_int8(p)
  assertEqual(p.pass_guint32(int8(-100)), uint32(4294967196));
function test_pass_guint32_uint8(p)
  assertEqual(p.pass_guint32(uint8(200)), uint32(200));
function test_pass_guint32_int16(p)
  assertEqual(p.pass_guint32(int16(400)), uint32(400));
function test_pass_guint32_uint16(p)
  assertEqual(p.pass_guint32(uint16(60000)), uint32(60000));
function test_pass_guint32_int32(p)
  assertEqual(p.pass_guint32(int32(100000)), uint32(100000));
function test_pass_guint32_uint32(p)
  assertEqual(p.pass_guint32(uint32(2147483658)), uint32(2147483658));
function test_pass_guint32_int64(p)
  assertEqual(p.pass_guint32(int64(1101659111524)), uint32(2147483748));
function test_pass_guint32_uint64(p)
  assertEqual(p.pass_guint32(uint64(1101659111524)), uint32(2147483748));
function test_pass_guint32_float(p)
  assertEqual(p.pass_guint32(single(2.3)), uint32(2));
function test_pass_guint32_double(p)
  assertEqual(p.pass_guint32(2.3), uint32(2));

function test_pass_gint64_true(p)
  assertEqual(p.pass_gint64(logical(1)), int64(1));
function test_pass_gint64_int8(p)
  assertEqual(p.pass_gint64(int8(-100)), int64(-100));
function test_pass_gint64_uint8(p)
  assertEqual(p.pass_gint64(uint8(200)), int64(200));
function test_pass_gint64_int16(p)
  assertEqual(p.pass_gint64(int16(400)), int64(400));
function test_pass_gint64_uint16(p)
  assertEqual(p.pass_gint64(uint16(60000)), int64(60000));
function test_pass_gint64_int32(p)
  assertEqual(p.pass_gint64(int32(100000)), int64(100000));
function test_pass_gint64_uint32(p)
  assertEqual(p.pass_gint64(uint32(2147483658)), int64(2147483658));
function test_pass_gint64_int64(p)
  assertEqual(p.pass_gint64(int64(1101659111524)), int64(1101659111524));
function test_pass_gint64_uint64(p)
  assertEqual(p.pass_gint64(uint64(9223373136366403684)), int64(-9223370937343147932));
function test_pass_gint64_float(p)
  assertEqual(p.pass_gint64(single(2.3)), int64(2));
function test_pass_gint64_double(p)
  assertEqual(p.pass_gint64(2.3), int64(2));

function test_pass_guint64_true(p)
  assertEqual(p.pass_guint64(logical(1)), uint64(1));
function test_pass_guint64_int8(p)
  assertEqual(p.pass_guint64(int8(-100)), uint64(18446744073709551516));
function test_pass_guint64_uint8(p)
  assertEqual(p.pass_guint64(uint8(200)), uint64(200));
function test_pass_guint64_int16(p)
  assertEqual(p.pass_guint64(int16(400)), uint64(400));
function test_pass_guint64_uint16(p)
  assertEqual(p.pass_guint64(uint16(60000)), uint64(60000));
function test_pass_guint64_int32(p)
  assertEqual(p.pass_guint64(int32(100000)), uint64(100000));
function test_pass_guint64_uint32(p)
  assertEqual(p.pass_guint64(uint32(2147483658)), uint64(2147483658));
function test_pass_guint64_int64(p)
  assertEqual(p.pass_guint64(int64(1101659111524)), uint64(1101659111524));
function test_pass_guint64_uint64(p)
  assertEqual(p.pass_guint64(uint64(9223373136366403684)), uint64(9223373136366403684));
function test_pass_guint64_float(p)
  assertEqual(p.pass_guint64(single(2.3)), uint64(2));
function test_pass_guint64_double(p)
  assertEqual(p.pass_guint64(2.3), uint64(2));

function test_pass_gfloat_true(p)
  assertEqual(p.pass_gfloat(logical(1)), single(1));
function test_pass_gfloat_int8(p)
  assertEqual(p.pass_gfloat(int8(-100)), single(-100));
function test_pass_gfloat_uint8(p)
  assertEqual(p.pass_gfloat(uint8(200)), single(200));
function test_pass_gfloat_int16(p)
  assertEqual(p.pass_gfloat(int16(400)), single(400));
function test_pass_gfloat_uint16(p)
  assertEqual(p.pass_gfloat(uint16(60000)), single(60000));
function test_pass_gfloat_int32(p)
  assertEqual(p.pass_gfloat(int32(100000)), single(100000));
function test_pass_gfloat_uint32(p)
  assertEqual(p.pass_gfloat(uint32(2147483658)), single(2147483658));
function test_pass_gfloat_int64(p)
  assertEqual(p.pass_gfloat(int64(1101659111524)), single(1101659111524));
function test_pass_gfloat_uint64(p)
  assertEqual(p.pass_gfloat(uint64(9223373136366403684)), single(9223373136366403684));
function test_pass_gfloat_float(p)
  assertEqual(p.pass_gfloat(single(2.3)), single(2.3));
function test_pass_gfloat_double(p)
  assertEqual(p.pass_gfloat(2.3e300), single(2.3e300));

function test_pass_gdouble_true(p)
  assertEqual(p.pass_gdouble(logical(1)), double(1));
function test_pass_gdouble_int8(p)
  assertEqual(p.pass_gdouble(int8(-100)), double(-100));
function test_pass_gdouble_uint8(p)
  assertEqual(p.pass_gdouble(uint8(200)), double(200));
function test_pass_gdouble_int16(p)
  assertEqual(p.pass_gdouble(int16(400)), double(400));
function test_pass_gdouble_uint16(p)
  assertEqual(p.pass_gdouble(uint16(60000)), double(60000));
function test_pass_gdouble_int32(p)
  assertEqual(p.pass_gdouble(int32(100000)), double(100000));
function test_pass_gdouble_uint32(p)
  assertEqual(p.pass_gdouble(uint32(2147483658)), double(2147483658));
function test_pass_gdouble_int64(p)
  assertEqual(p.pass_gdouble(int64(1101659111524)), double(1101659111524));
function test_pass_gdouble_uint64(p)
  assertEqual(p.pass_gdouble(uint64(9223373136366403684)), double(9223373136366403684));
function test_pass_gdouble_float(p)
  assertElementsAlmostEqual(p.pass_gdouble(single(2.3)), double(2.3));
function test_pass_gdouble_double(p)
  assertEqual(p.pass_gdouble(2.3e300), double(2.3e300));

function test_pass_out_bool(p)
  assertEqual(p.pass_out_bool(logical(1)), logical(1));
function test_pass_out_gint8(p)
  assertEqual(p.pass_out_gint8(int8(-100)), int8(-100));
function test_pass_out_guint8(p)
  assertEqual(p.pass_out_guint8(uint8(200)), uint8(200));
function test_pass_out_gint16(p)
  assertEqual(p.pass_out_gint16(int16(400)), int16(400));
function test_pass_out_guint16(p)
  assertEqual(p.pass_out_guint16(uint16(60000)), uint16(60000));
function test_pass_out_gint32(p)
  assertEqual(p.pass_out_gint32(int32(100000)), int32(100000));
function test_pass_out_guint32(p)
  assertEqual(p.pass_out_guint32(uint32(2147483658)), uint32(2147483658));
function test_pass_out_gint64(p)
  assertEqual(p.pass_out_gint64(int64(1101659111524)), int64(1101659111524));
function test_pass_out_guint64(p)
  assertEqual(p.pass_out_guint64(uint64(9223373136366403684)), uint64(9223373136366403684));
function test_pass_out_gfloat(p)
  assertEqual(p.pass_out_gfloat(single(2.3)), single(2.3));
function test_pass_out_gdouble(p)
  assertEqual(p.pass_out_gdouble(2.3e300), double(2.3e300));

function test_pass_inout_bool(p)
  assertEqual(p.pass_inout_bool(logical(1)), logical(1));
function test_pass_inout_gint8(p)
  assertEqual(p.pass_inout_gint8(int8(-100)), int8(-100));
function test_pass_inout_guint8(p)
  assertEqual(p.pass_inout_guint8(uint8(200)), uint8(200));
function test_pass_inout_gint16(p)
  assertEqual(p.pass_inout_gint16(int16(400)), int16(400));
function test_pass_inout_guint16(p)
  assertEqual(p.pass_inout_guint16(uint16(60000)), uint16(60000));
function test_pass_inout_gint32(p)
  assertEqual(p.pass_inout_gint32(int32(100000)), int32(100000));
function test_pass_inout_guint32(p)
  assertEqual(p.pass_inout_guint32(uint32(2147483658)), uint32(2147483658));
function test_pass_inout_gint64(p)
  assertEqual(p.pass_inout_gint64(int64(1101659111524)), int64(1101659111524));
function test_pass_inout_guint64(p)
  assertEqual(p.pass_inout_guint64(uint64(9223373136366403684)), uint64(9223373136366403684));
function test_pass_inout_gfloat(p)
  assertEqual(p.pass_inout_gfloat(single(2.3)), single(2.3));
function test_pass_inout_gdouble(p)
  assertEqual(p.pass_inout_gdouble(2.3e300), double(2.3e300));

function test_prod(p)
  assertEqual(p.prod(2, 3), 6);

function test_pass_string(p)
  x = 'asdéf';
  assertEqual(p.pass_string(x), x);
function test_pass_out_string(p)
  x = 'asdéf';
  assertEqual(p.pass_out_string(x), x);
function test_pass_intout_string(p)
  x = 'asdéf';
  assertEqual(p.pass_inout_string(x), x);

%% Test arrays and lists

function test_get_fixed_array(p)
  assertEqual(p.get_fixed_array(), int64([1 2 3]));
function test_get_zero_term_array(p)
  assertEqual(p.get_zero_term_array(), int64([1 2 3]));

function test_pass_array_bool(p)
  x = logical([1 1 0]);
  assertEqual(p.pass_array_bool(x, length(x)), x);
function test_pass_array_gint8(p)
  x = int8([1 1 0]);
  assertEqual(p.pass_array_gint8(x, length(x)), x);
function test_pass_array_guint8(p)
  x = uint8([1 1 0]);
  assertEqual(p.pass_array_guint8(x, length(x)), x);
function test_pass_array_gint16(p)
  x = int16([1 1 0]);
  assertEqual(p.pass_array_gint16(x, length(x)), x);
function test_pass_array_guint16(p)
  x = uint16([1 1 0]);
  assertEqual(p.pass_array_guint16(x, length(x)), x);
function test_pass_array_gint32(p)
  x = int32([1 1 0]);
  assertEqual(p.pass_array_gint32(x, length(x)), x);
function test_pass_array_guint32(p)
  x = uint32([1 1 0]);
  assertEqual(p.pass_array_guint32(x, length(x)), x);
function test_pass_array_gint64(p)
  x = int64([1 1 0]);
  assertEqual(p.pass_array_gint64(x, length(x)), x);
function test_pass_array_guint64(p)
  x = uint64([1 1 0]);
  assertEqual(p.pass_array_guint64(x, length(x)), x);
function test_pass_array_gfloat(p)
  x = single([1.2 3.4 5.6]);
  assertEqual(p.pass_array_gfloat(x, length(x)), x);
function test_pass_array_gdouble(p)
  x = ([1.2 3.4 5.6]);
  assertEqual(p.pass_array_gdouble(x, length(x)), x);
function test_pass_array_string(p)
  x = {'qwer', 'asdf', 'zxcv'};
  assertEqual(p.pass_array_string(x, length(x)), x);

function test_pass_array_bool_double(p)
  x = ([1 1 0]);
  assertEqual(p.pass_array_bool(x, length(x)), logical(x));
function test_pass_array_gint8_double(p)
  x = ([1 1 0]);
  assertEqual(p.pass_array_gint8(x, length(x)), int8(x));
function test_pass_array_guint8_double(p)
  x = ([1 1 0]);
  assertEqual(p.pass_array_guint8(x, length(x)), uint8(x));
function test_pass_array_gint16_double(p)
  x = ([1 1 0]);
  assertEqual(p.pass_array_gint16(x, length(x)), int16(x));
function test_pass_array_guint16_double(p)
  x = ([1 1 0]);
  assertEqual(p.pass_array_guint16(x, length(x)), uint16(x));
function test_pass_array_gint32_double(p)
  x = ([1 1 0]);
  assertEqual(p.pass_array_gint32(x, length(x)), int32(x));
function test_pass_array_guint32_double(p)
  x = ([1 1 0]);
  assertEqual(p.pass_array_guint32(x, length(x)), uint32(x));
function test_pass_array_gint64_double(p)
  x = ([1 1 0]);
  assertEqual(p.pass_array_gint64(x, length(x)), int64(x));
function test_pass_array_guint64_double(p)
  x = ([1 1 0]);
  assertEqual(p.pass_array_guint64(x, length(x)), uint64(x));
function test_pass_array_gfloat_double(p)
  x = ([1.2 3.4 5.6]);
  assertElementsAlmostEqual(p.pass_array_gfloat(x, length(x)), single(x));

function test_pass_garray_bool(p)
  x = logical([1 1 0]);
  assertEqual(p.pass_garray_bool(x), x);
function test_pass_garray_gint8(p)
  x = int8([1 1 0]);
  assertEqual(p.pass_garray_gint8(x), x);
function test_pass_garray_guint8(p)
  x = uint8([1 1 0]);
  assertEqual(p.pass_garray_guint8(x), x);
function test_pass_garray_gint16(p)
  x = int16([1 1 0]);
  assertEqual(p.pass_garray_gint16(x), x);
function test_pass_garray_guint16(p)
  x = uint16([1 1 0]);
  assertEqual(p.pass_garray_guint16(x), x);
function test_pass_garray_gint32(p)
  x = int32([1 1 0]);
  assertEqual(p.pass_garray_gint32(x), x);
function test_pass_garray_guint32(p)
  x = uint32([1 1 0]);
  assertEqual(p.pass_garray_guint32(x), x);
function test_pass_garray_gint64(p)
  x = int64([1 1 0]);
  assertEqual(p.pass_garray_gint64(x), x);
function test_pass_garray_guint64(p)
  x = uint64([1 1 0]);
  assertEqual(p.pass_garray_guint64(x), x);
function test_pass_garray_gfloat(p)
  x = single([1.2 3.4 5.6]);
  assertEqual(p.pass_garray_gfloat(x), x);
function test_pass_garray_gdouble(p)
  x = ([1.2 3.4 5.6]);
  assertEqual(p.pass_garray_gdouble(x), x);
function test_pass_garray_string(p)
  x = {'qwer', 'asdf', 'zxcv'};
  assertEqual(p.pass_garray_string(x), x);

function test_pass_glist_bool(p)
  x = logical([1 1 0]);
  assertEqual(p.pass_glist_bool(x), x);
function test_pass_glist_gint8(p)
  x = int8([1 1 0]);
  assertEqual(p.pass_glist_gint8(x), x);
function test_pass_glist_guint8(p)
  x = uint8([1 1 0]);
  assertEqual(p.pass_glist_guint8(x), x);
function test_pass_glist_gint16(p)
  x = int16([1 1 0]);
  assertEqual(p.pass_glist_gint16(x), x);
function test_pass_glist_guint16(p)
  x = uint16([1 1 0]);
  assertEqual(p.pass_glist_guint16(x), x);
function test_pass_glist_gint32(p)
  x = int32([1 1 0]);
  assertEqual(p.pass_glist_gint32(x), x);
function test_pass_glist_guint32(p)
  x = uint32([1 1 0]);
  assertEqual(p.pass_glist_guint32(x), x);
function test_pass_glist_gint64(p)
  x = int64([1 1 0]);
  assertEqual(p.pass_glist_gint64(x), x);
function test_pass_glist_guint64(p)
  x = uint64([1 1 0]);
  assertEqual(p.pass_glist_guint64(x), x);
function test_pass_glist_gfloat(p)
  x = single([1.2 3.4 5.6]);
  assertEqual(p.pass_glist_gfloat(x), x);
function test_pass_glist_gdouble(p)
  x = ([1.2 3.4 5.6]);
  assertEqual(p.pass_glist_gdouble(x), x);
function test_pass_glist_string(p)
  x = {'qwer', 'asdf', 'zxcv'};
  assertEqual(p.pass_glist_string(x), x);

function test_pass_gslist_bool(p)
  x = logical([1 1 0]);
  assertEqual(p.pass_gslist_bool(x), x);
function test_pass_gslist_gint8(p)
  x = int8([1 1 0]);
  assertEqual(p.pass_gslist_gint8(x), x);
function test_pass_gslist_guint8(p)
  x = uint8([1 1 0]);
  assertEqual(p.pass_gslist_guint8(x), x);
function test_pass_gslist_gint16(p)
  x = int16([1 1 0]);
  assertEqual(p.pass_gslist_gint16(x), x);
function test_pass_gslist_guint16(p)
  x = uint16([1 1 0]);
  assertEqual(p.pass_gslist_guint16(x), x);
function test_pass_gslist_gint32(p)
  x = int32([1 1 0]);
  assertEqual(p.pass_gslist_gint32(x), x);
function test_pass_gslist_guint32(p)
  x = uint32([1 1 0]);
  assertEqual(p.pass_gslist_guint32(x), x);
function test_pass_gslist_gint64(p)
  x = int64([1 1 0]);
  assertEqual(p.pass_gslist_gint64(x), x);
function test_pass_gslist_guint64(p)
  x = uint64([1 1 0]);
  assertEqual(p.pass_gslist_guint64(x), x);
function test_pass_gslist_gfloat(p)
  x = single([1.2 3.4 5.6]);
  assertEqual(p.pass_gslist_gfloat(x), x);
function test_pass_gslist_gdouble(p)
  x = ([1.2 3.4 5.6]);
  assertEqual(p.pass_gslist_gdouble(x), x);
function test_pass_gslist_string(p)
  x = {'qwer', 'asdf', 'zxcv'};
  assertEqual(p.pass_gslist_string(x), x);

%% Test GType arguments

function test_pass_gtype(p)
  assertEqual(p.pass_gtype(p.Thing), p.Thing);
function test_pass_out_gtype(p)
  assertEqual(p.pass_out_gtype(p.Thing), p.Thing);
function test_pass_inout_gtype(p)
  assertEqual(p.pass_inout_gtype(p.Thing), p.Thing);
function test_pass_array_gtype(p)
  x = {p.Noisy p.Thing p.Subthing};
  assertEqual(p.pass_array_gtype(x, length(x)), x);
function test_pass_garray_gtype(p)
  x = {p.Noisy p.Thing p.Subthing};
  assertEqual(p.pass_garray_gtype(x), x);
function test_pass_glist_gtype(p)
  x = {p.Noisy p.Thing p.Subthing};
  assertEqual(p.pass_glist_gtype(x), x);
function test_pass_gslist_gtype(p)
  x = {p.Noisy p.Thing p.Subthing};
  assertEqual(p.pass_gslist_gtype(x), x);

%% Test GObject arguments

function test_pass_gobject(p)
  o = p.Thing();
  assertEqual(p.pass_gobject(o), o);
function test_pass_gobject_null(p)
  assertEqual(p.pass_gobject(glib.GObject.NULL), glib.GObject.NULL);
function test_pass_out_gobject(p)
  o = p.Thing();
  assertEqual(p.pass_out_gobject(o), o);
function test_pass_out_gobject_null(p)
  assertEqual(p.pass_out_gobject(glib.GObject.NULL), glib.GObject.NULL);
function test_pass_inout_gobject(p)
  o = p.Thing();
  assertEqual(p.pass_inout_gobject(o), o);
function test_pass_inout_gobject_null(p)
  assertEqual(p.pass_inout_gobject(glib.GObject.NULL), glib.GObject.NULL);
function test_thing_zero(p)
  o = p.Thing('prop_int', 3);
  assertTrue(o.zero() == 3);
function test_thing_one(p)
  o = p.Thing('prop_int', 3);
  assertEqual(o.one(2.5), 2.5*3);
function test_thing_two(p)
  o = p.Thing();
  assertEqual(o.two(2.5, 3), 2.5*3);
function test_thing_pass_out_gint32(p)
  o = p.Thing();
  assertEqual(o.pass_out_gint32(25), int32(25));

%% Test GObject properties

function test_thing_prop_bool(p)
  o = p.Thing();
  o.prop_bool = true;
  assertEqual(o.prop_bool, true);
function test_thing_prop_char(p)
  o = p.Thing();
  o.prop_char = 'w';
  assertEqual(o.prop_char, 'w');
function test_thing_prop_uchar(p)
  o = p.Thing();
  o.prop_uchar = 'w';
  assertEqual(o.prop_uchar, 'w');
function test_thing_prop_int_int8(p)
  o = p.Thing();
  o.prop_int = int8(35);
  assertTrue(o.prop_int == int8(35));
function test_thing_prop_int_int16(p)
  o = p.Thing();
  o.prop_int = int16(350);
  assertTrue(o.prop_int == int16(350));
function test_thing_prop_int_int32(p)
  o = p.Thing();
  o.prop_int = int32(95435);
  assertTrue(o.prop_int == int32(95435));
function test_thing_prop_uint_uint8(p)
  o = p.Thing();
  o.prop_uint = uint8(35);
  assertTrue(o.prop_uint == uint8(35));
function test_thing_prop_uint_uint16(p)
  o = p.Thing();
  o.prop_uint = uint16(350);
  assertTrue(o.prop_uint == uint16(350));
function test_thing_prop_uint_uint32(p)
  o = p.Thing();
  o.prop_uint = uint32(95435);
  assertTrue(o.prop_uint == uint32(95435));
function test_thing_prop_long(p)
  o = p.Thing();
  o.prop_long = int32(9542);
  assertTrue(o.prop_long == int32(9542));
function test_thing_prop_ulong(p)
  o = p.Thing();
  o.prop_ulong = int32(9542);
  assertTrue(o.prop_ulong == int32(9542));
function test_thing_prop_int64(p)
  o = p.Thing();
  o.prop_int64 = int64(95434252346522);
  assertEqual(o.prop_int64, int64(95434252346522));
function test_thing_prop_uint64(p)
  o = p.Thing();
  o.prop_uint64 = uint64(95434252346522);
  assertEqual(o.prop_uint64, uint64(95434252346522));
function test_thing_prop_float(p)
  o = p.Thing();
  o.prop_float = single(2.3);
  assertEqual(o.prop_float, single(2.3));
function test_thing_prop_double(p)
  o = p.Thing();
  o.prop_double = (2.3);
  assertEqual(o.prop_double, (2.3));
function test_thing_prop_string(p)
  o = p.Thing();
  x = 'asdéf';
  o.prop_string = x;
  assertEqual(o.prop_string, x);
function test_thing_prop_gtype(p)
  o = p.Thing();
  o.prop_gtype = p.Subthing;
  assertEqual(o.prop_gtype, p.Subthing);
function test_thing_prop_object(p)
  x = p.Subthing();
  o = p.Thing();
  o.prop_object = x;
  assertEqual(o.prop_object, x);
function test_thing_fetch_null(p)
  o = p.Thing();
  assertEqual(o.prop_object, glib.GObject.NULL);
function test_thing_prop_object_null(p)
  x = p.Subthing();
  o = p.Thing();
  o.prop_object = x;
  o.prop_object = glib.GObject.NULL;
  assertEqual(o.prop_object, glib.GObject.NULL);

%% Test reference counting

function test_createDispose(p)
  initial_count = p.Thing.get_count();
  o = p.Thing();
  o = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createCallDispose(p)
  initial_count = p.Thing.get_count();
  o = p.Thing();
  o.void();
  o = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createStoreReleaseDispose(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  o.prop_object = x;
  o.prop_object = glib.GObject.NULL;
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createStoreFetchDisposeReleaseDispose(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  o.prop_object = x;
  y = o.prop_object;
  assertEqual(x, y);
  y = 0;
  o.prop_object = glib.GObject.NULL;
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createStoreFetchReleaseDisposeDispose(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  o.prop_object = x;
  y = o.prop_object;
  o.prop_object = glib.GObject.NULL;
  assertEqual(x, y);
  y = 0;
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createStoreDisposeRelease(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  o.prop_object = x;
  x = 0;
  o.prop_object = glib.GObject.NULL;
  assertEqual(p.Thing.get_count(), initial_count);
  % Use trace output to (check that wrapper is actually destroyed)
function test_createStoreDisposeFetchReleaseDispose(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  o.prop_object = x;
  x = 0;
  x = o.prop_object;
  o.prop_object = glib.GObject.NULL;
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createStoreDisposeFetchDisposeRelease(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  o.prop_object = x;
  x = 0;
  x = o.prop_object;
  x = 0;
  o.prop_object = glib.GObject.NULL;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createConstructDisposeConstructedDispose(p)
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  o = p.Thing('prop_object', x);
  o = 0;
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createConstructDisposeDisposeConstructed(p)
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  o = p.Thing('prop_object', x);
  x = 0;
  o = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createTransferReleaseDispose(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  o.receive_object(x, glib.GObject.NULL);
  o.prop_object = glib.GObject.NULL;
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createTransferDisposeRelease(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  o.receive_object(x, glib.GObject.NULL);
  x = 0;
  o.prop_object = glib.GObject.NULL;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createTransferNoneInterruptedDispose(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  % This call will fail *after* processing object x, but before x is stored
  try
    o.dup_object(x, 24);
  catch
  end
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_createTransferFullInterruptedDispose(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = p.Subthing();
  % This call will fail *after* processing object x, but before x is stored
  try
    o.receive_object(x, 24);
  catch
  end
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_makeStoredDisposeRelease(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = o.make_stored_subthing();
  x = 0;
  o.prop_object = glib.GObject.NULL;
  assertEqual(p.Thing.get_count(), initial_count);
function test_makeStoredReleaseDispose(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = o.make_stored_subthing();
  o.prop_object = glib.GObject.NULL;
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_makeStoredReleaseStoreDisposeRelease(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = o.make_stored_subthing();
  o.prop_object = glib.GObject.NULL;
  o.prop_object = x;
  x = 0;
  o.prop_object = glib.GObject.NULL;
  assertEqual(p.Thing.get_count(), initial_count);
function test_makeStoredReleaseStoreReleaseDispose(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = o.make_stored_subthing();
  o.prop_object = glib.GObject.NULL;
  o.prop_object = x;
  o.prop_object = glib.GObject.NULL;
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_makeUnstoredDispose(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = o.make_subthing();
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_makeUnstoredStoreDisposeRelease(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = o.make_subthing();
  o.prop_object = x;
  x = 0;
  o.prop_object = glib.GObject.NULL;
  assertEqual(p.Thing.get_count(), initial_count);
function test_makeUnstoredStoreReleaseDispose(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = o.make_subthing();
  o.prop_object = x;
  o.prop_object = glib.GObject.NULL;
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
function test_doubleWrap(p)
  o = p.Thing();
  initial_count = p.Thing.get_count();
  x = o.make_stored_subthing();
  assertEqual(p.pass_gobject(x), o.prop_object);
  o.prop_object = glib.GObject.NULL;
  x = 0;
  assertEqual(p.Thing.get_count(), initial_count);
